package com.vue.dao.impl;

import com.vue.dao.VueDaoCm;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2018/6/11.
 * 注入不同的session工厂，连接到不同的数据库
 */
@Repository()
public class VueDaoCmImpl<T> implements VueDaoCm<T> {

    @Resource
    private SessionFactory sessionFactorycm;

    private Session getCurrentSession() {
        return this.sessionFactorycm.getCurrentSession();
    }

    @Override
    public List<T> find(String hql) {
        return this.getCurrentSession().createQuery(hql).list();
    }

    public T get(Class<T> c, Serializable id) {
        return (T)this.getCurrentSession().get(c, id);
    }


}
